home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / usr_-_Usr_Files / INCLUDE / ASSERT.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  3KB  |  119 lines

  1. /* Copyright (C) 1991, 1992, 1994, 1995 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    ANSI Standard: 4.2 DIAGNOSTICS    <assert.h>
  21.  */
  22.  
  23. #ifdef    _ASSERT_H
  24.  
  25. #undef    _ASSERT_H
  26. #undef    assert
  27. #undef  assert_perror
  28.  
  29. #endif /* assert.h    */
  30.  
  31. #define    _ASSERT_H    1
  32. #include <features.h>
  33.  
  34. /* void assert (int expression);
  35.  
  36.    If NDEBUG is defined, do nothing.
  37.    If not, and EXPRESSION is zero, print an error message and abort.  */
  38.  
  39. #ifdef    NDEBUG
  40.  
  41. #define    assert(expr)        ((void) 0)
  42.  
  43. /* void assert_perror (int errnum);
  44.  
  45.    If NDEBUG is defined, do nothing.  If not, and ERRNUM is not zero, print an
  46.    error message with the error text for ERRNUM and abort.
  47.    (This is a GNU extension.) */
  48.  
  49. #ifdef    __USE_GNU
  50. #define    assert_perror(errnum)    ((void) 0)
  51. #endif
  52.  
  53. #else /* Not NDEBUG.  */
  54.  
  55. #include <sys/cdefs.h>
  56.  
  57. __BEGIN_DECLS
  58.  
  59. #ifdef __SVR4_I386_ABI_L1__
  60.  
  61. extern void __assert(const char *, const char *, int)
  62.      __attribute__ ((__noreturn__));
  63.  
  64. #else
  65.  
  66. /* This prints an "Assertion failed" message and aborts.  */
  67. extern void __assert_fail __P ((__const char *__assertion,
  68.                 __const char *__file,
  69.                 unsigned int __line,
  70.                 __const char *__function))
  71.      __attribute__ ((__noreturn__));
  72.  
  73. /* Likewise, but prints the error text for ERRNUM.  */
  74. extern void __assert_perror_fail __P ((int __errnum,
  75.                        __const char *__file,
  76.                        unsigned int __line,
  77.                        __const char *__function))
  78.      __attribute__ ((__noreturn__));
  79.  
  80. #endif
  81.  
  82. __END_DECLS
  83.  
  84. #ifdef __SVR4_I386_ABI_L1__
  85.  
  86. #define    assert(expr)                                  \
  87.   ((void) ((expr) ||                                  \
  88.        (__assert (__STRING(expr),                      \
  89.                __FILE__, __LINE__), 0)))
  90.  
  91. #else /* __SVR4_I386_ABI_L1__ */
  92.  
  93. #define    assert(expr)                                  \
  94.   ((void) ((expr) ||                                  \
  95.        (__assert_fail (__STRING(expr),                      \
  96.                __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
  97.  
  98. #ifdef    __USE_GNU
  99. #define assert_perror(errnum)                              \
  100.   ((void) ((errnum) && (__assert_perror_fail ((errnum),                  \
  101.                           __FILE__, __LINE__,          \
  102.                           __ASSERT_FUNCTION), 0)))
  103. #endif
  104.  
  105. /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
  106.    which contains the name of the function currently being defined.
  107.    This is broken in G++ before version 2.6.  */
  108. #if (!defined (__GNUC__) || __GNUC__ < 2 || \
  109.      __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
  110. #define __ASSERT_FUNCTION    ((__const char *) 0)
  111. #else
  112. #define __ASSERT_FUNCTION    __PRETTY_FUNCTION__
  113. #endif
  114.  
  115. #endif /* __SVR4_I386_ABI_L1__ */
  116.  
  117. #endif /* NDEBUG.  */
  118.  
  119.